/* eslint-disable */
import axios from "axios";
import { config } from "../config";
class Base {
  async _axiosCreate(token) {
    // axios.defaults.baseURL = "https://exapi.jxbscbd.com";
    axios.defaults.baseURL = config.api_url;
    axios.defaults.headers = {
      "content-type": "application/json",
      Authorization: "Bearer " + token,
    };
  }
}

class UserCommon extends Base {
  constructor() {
    super();
    this.source = "";
    this.userId = "";
    this.token = "";
    this.userAvatar = "";
    this.nickName = "";
  }

  async getSource(url) {
    let source;
    url = url.split("?")[1].split("&");
    source = url.filter((el) => el.search("source") !== -1);
    this.source = source[0].split("=")[1];
    let userId = url.filter((el) => el.search("userId") !== -1);
    this.userId = userId[0].split("=")[1];
    let token = url.filter((el) => el.search("token") !== -1);
    this.token = token[0].split("=")[1];
    let userAvatar = url.filter((el) => el.search("userAvatar") !== -1);
    this.userAvatar = userAvatar[0].split("=")[1];
    let nickName = url.filter((el) => el.search("nickName") !== -1);
    this.nickName = decodeURIComponent(nickName[0].split("=")[1]);
    await this._axiosCreate(this.token);
    return {
      source: this.source,
      userId: this.userId,
      token: this.token,
      userAvatar: this.userAvatar,
      nickName: this.nickName,
    };
    // zhuge.track("威士忌互动H5-用户来源", {
    //   source: source,
    //   userId: userId,
    // });
  }

  async lottery(userId,activityId) {
    const {data} = await axios({
      method: 'post',
      url: '/gateway/shop/prize/lottery',
      data: {
        userId,
        activityId,
      },
    })
    return data
  }

  async getActivityInfo() {
    const res = await axios({
      method: 'get',
      url: '/gateway/shop/prize/activity/getActivityInfo',
    })
    let active = {}
    if (res.data.success) {
      active.prizes = res.data.data.prizes.list
      active.info = res.data.data.activity
    }
    return active
  }
}

export { Base, UserCommon };
